package com.cweb.admin.controller;


import com.cweb.admin.configuration.annotation.NoAuthorityCheck;
import com.cweb.admin.configuration.annotation.NoLoginCheck;
import com.cweb.admin.model.sys.sys_user_info.entity.SysUserInfo;
import com.cweb.admin.model.sys.sys_user_info.service.SysUserInfoProcessService;
import com.cweb.admin.model.sys.sys_user_info.service.SysUserInfoService;
import com.cweb.framework.annotation.Remark;
import com.cweb.framework.base.controller.BaseController;
import com.cweb.framework.pojo.BaseResponse;
import com.cweb.framework.pojo.CustomException;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统-用户信息表 前端控制器
 * @author changfan
 */
@RestController
@RequestMapping("login/user")
public class UserController extends BaseController {
    @Autowired
    private SysUserInfoService sysUserInfoService;
    @Autowired
    private SysUserInfoProcessService sysUserInfoProcessService;


    @RequestMapping("register")
    @Remark(name = "用户注册", describe = "")
    @NoLoginCheck
    public BaseResponse register(SysUserInfo param) throws CustomException {
        return new BaseResponse(sysUserInfoService.register(param));
    }

    @RequestMapping("login")
    @Remark(name = "用户登录", describe = "")
    @NoLoginCheck
    public BaseResponse login(SysUserInfo param) throws CustomException {
        return new BaseResponse(sysUserInfoService.login(param));
    }

    @RequestMapping("logout")
    @Remark(name = "用户登出", describe = "")
    @NoLoginCheck
    public BaseResponse logout(SysUserInfo param) throws CustomException {
        return new BaseResponse();
    }

    @RequestMapping("getCodeImg")
    @Remark(name = "取得验证码图片", describe = "")
    @NoLoginCheck
    public BaseResponse getCodeImg(SysUserInfo param) throws CustomException {
        return new BaseResponse();
    }

    @RequestMapping("getInfo")
    @Remark(name = "取得用户信息", describe = "")
    @NoAuthorityCheck
    public BaseResponse getInfo(SysUserInfo param) throws CustomException {
        return new BaseResponse(sysUserInfoProcessService.get());
    }

    @RequestMapping("id")
    @Remark(name = "id查询", describe = "")
    public BaseResponse id(@Param(value = "id") Long id) throws CustomException {
        return new BaseResponse(sysUserInfoProcessService.showUserInfo(id));
    }

    @RequestMapping("countInfo")
    @Remark(name = "相关的统计信息", describe = "")
    public BaseResponse countInfo(@Param(value = "id") Long id) throws CustomException {
        return new BaseResponse(sysUserInfoProcessService.userCountInfo(id));
    }

    @RequestMapping("changeUserInfo")
    @Remark(name = "当前用户修改信息", describe = "")
    @NoAuthorityCheck
    public BaseResponse changeUserInfo(SysUserInfo param) throws CustomException {
        return new BaseResponse(sysUserInfoProcessService.processChangeUserInfo(param));
    }

    @RequestMapping("changePassword")
    @Remark(name = "当前用户更改密码", describe = "")
    @NoAuthorityCheck
    public BaseResponse changePassword(String password, String oldPassword) throws CustomException {
        return new BaseResponse(sysUserInfoProcessService.processChangePassowrd(password, oldPassword));
    }
}

